#include<iostream>
using namespace std;

void rearrange_1(){
    int a[7] = {0,3,0,2,1,0,0};
    int i,j;
    for(i=0,j=6;i<j;i++,j--){
        while(a[i]==0) i++;
        while(a[j]) j--;
        if(i<j){
            a[j]=a[i];
            a[i] =0;
        }
    }
    for(i=0;i<7;i++)
        printf("%d",a[i]);
}

void rearrange_2(){
    const static int len = 8;
    int a[len] = {0,4,0,3,2,0,0,1};
    int i,j,k;
    for(i=0,j=len-1;i<j;){
        while(a[i]==0) i++;
        while(a[j]) j--;
        if(i<j){
            for(k=j;k>i;k--)
                a[k] = a[k-1];
            a[k] = 0;
            i++;
            printf("%d ,%d\n",i,j);
        }
    }
    for(i=0;i<len;i++)
        printf("%d",a[i]);
}

void rearrange_3(){
    const static int len = 8;
    int a[len] = {0,4,0,3,2,0,0,1};
    int i,k=len-1;
    for(i=len-1;i>=0;i--){
        if(a[i]!=0){
            if(a[k]==0){
                a[k] = a[i];
                a[i] = 0;
            }
            k--;
        }
    }
    for(i=0;i<len;i++)
        printf("%d",a[i]);
}

int main(){
    rearrange_3();
    return 0;
}
